feat: Add temp dir option#2891
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for configuring Task’s temporary directory via .taskrc.yml (temp-dir) and the TASK_TEMP_DIR environment variable, wiring the resolved value into executor setup and updating docs/schemas accordingly.
Changes:
- Add
temp-dirto taskrc AST + merge logic, and add unit tests covering parsing/merge precedence. - Introduce
Executor.TempDirPath/WithTempDirPathand use it duringExecutorsetup to buildExecutor.TempDir. - Update website docs and JSON schema for
.taskrc.yml, plus VS Code YAML schema mapping.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| website/src/public/schema-taskrc.json | Adds temp-dir to the taskrc JSON schema. |
| website/src/docs/reference/config.md | Documents the new temp-dir config option and adds it to the example config. |
| taskrc/taskrc_test.go | Adds tests for temp-dir parsing and merge precedence across config locations. |
| taskrc/ast/taskrc.go | Adds TempDir field and merges it during TaskRC merge. |
| setup.go | Adds temp-dir resolution helper and uses it to initialize Executor.TempDir. |
| internal/flags/flags.go | Reads temp-dir from env/taskrc into executor options (no CLI flag). |
| executor.go | Adds TempDirPath + WithTempDirPath option for unresolved temp dir configuration. |
| .vscode/settings-sample.json | Adds YAML schema association for .taskrc.* files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func (e *Executor) configuredTempDirPath() string { | ||
| // Priority: OS env > taskrc/env > default | ||
| if tempDir := env.GetTaskEnv("TEMP_DIR"); tempDir != "" { | ||
| return tempDir | ||
| } | ||
| if e.TempDirPath != "" { | ||
| return e.TempDirPath | ||
| } | ||
| return ".task" | ||
| } |
There was a problem hiding this comment.
The precedence behavior is same as internal/flags/flags.go:319:
// getConfig extracts a config value with priority: env var > taskrc config > fallback
func getConfig[T any](config *taskrcast.TaskRC, envKey string, fieldFunc func() *T, fallback T) T {
// xxx
};| func (e *Executor) configuredTempDirPath() string { | ||
| // Priority: OS env > taskrc/env > default | ||
| if tempDir := env.GetTaskEnv("TEMP_DIR"); tempDir != "" { | ||
| return tempDir | ||
| } |
There was a problem hiding this comment.
I think it has some file reading order issue, so it doesn't support this for now.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Register --temp-dir as a real pflag instead of assigning the variable directly in the flags package, so it follows the same flag+config pattern as every other option (e.g. --remote-cache-dir). Drop the configuredTempDirPath helper: now that the flags layer owns env resolution (like every other option), it collapses to cmp.Or(TempDirPath, ".task"), inlined into setupTempDir. This also fixes the previous inverted precedence where TASK_TEMP_DIR was read above the resolved path and would win over the flag. Document the --temp-dir flag in the CLI reference.
vmaerten
left a comment
There was a problem hiding this comment.
Thanks! I've added the CLI support as well
At first I thought this should only be a fixed setting, so I didn't plan to add CLI support to it. Anyway, it also makes sense👍 |
Close #998
Support
temp-diroption in.taskrc.ymland env variable. Haven't supported option or configuration in dotenv andTaskfile.ymldue to some file reading order issues.AI helped with generating some unit test in this PR.